import { Toast } from "vant";

const sendSMS = {
  data(){
    return {
      sendsms: false,
      sendsmstext: "发送验证码",
      sendType: ''
    }
  },
  methods: {
    sendSMS(phone) {
      // console.log(phone)
      if(!phone){
        Toast('手机号不能为空')
        return false
      }
      if (this.sendsms == false) {

        let timer = null

        this.$http
          .post(this.$urls.FSDX, {
            phone: phone,
            type: this.sendType
          })
          .then(res => {
            console.log(res)
            if (res.data.code == 200) {
              Toast.success("发送成功");

              // 倒计时处理
              this.sendsmstext = 60;
              timer = setInterval(() => {
                if (this.sendsmstext == 0) {
                  clearInterval(timer);
                  this.sendsms = false;
                  this.sendsmstext = "发送验证码";
                } else {
                  this.sendsmstext -= 1;
                }
              }, 1000);
              this.sendsms = true;


            } else {
              Toast(res.data.msg);
            }
          });
      } else {
        Toast("不可频繁发送");
      }
    }
  }
}

export default sendSMS